using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Xna.Framework;
using HappySprite.SceneGraph;

namespace HappySprite.Tests
{
    [TestClass]
    public class SceneGraphTests
    {
        [TestMethod]
        public void ParentTest()
        {
            SceneItem parent = new SceneItem();
            SceneItem child = new SceneItem();

            parent.Add(child);
            Assert.AreEqual(parent, child.Parent);
        }

        [TestMethod]
        public void EmptyChildernTest()
        {
            // Should be able to iterate an empty childern collection
            // without null exception when using lazy object creation
            SceneItem item = new SceneItem();

            int count = 0;
            foreach (SceneItem child in item.Childern)
                count++;

            Assert.AreEqual(0, count);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void PreventInfiniteRecursionTest()
        {
            // Can't add self as a child of self
            SceneItem item = new SceneItem();
            item.Add(item);
        }

        [TestMethod]
        public void TransformTest()
        {
            SceneItem root = new SceneItem();
            SceneItem child = new SceneItem();

            root.Add(child);

            Quaternion q = Quaternion.CreateFromYawPitchRoll(
                MathHelper.ToRadians(10f),
                MathHelper.ToRadians(20f),
                MathHelper.ToRadians(30f));

            root.Local.Rotation.Rotate(q);

            Assert.AreEqual(q, root.World.Rotation.Quaternion);
            Assert.AreEqual(root.World.Rotation.Quaternion, child.World.Rotation.Quaternion);
        }
    }
}
